/**@Title   Main.java
 * @Package com.gong.spring.beans
 * @Desc    
 * @Author  GongWenhua
 * @Date    2017年5月8日 上午9:46:45
 * @Version 1.0
*/
package com.gong.spring.beans;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gong.spring.beans.scope.Car;

public class Main {
	public static void main(String[] args) {
		/*
		//创建对象
		HelloWorld helloWorld = new HelloWorld();
		//为对象赋值
		helloWorld.setName("gong");
		*/
		
		
		
		//创建对象和为对象赋值可以交给Spring
		
		//1.创建SpringIOC容器
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		//2.从IOC容器中获取Bean示例
		HelloWorld helloWorld = (HelloWorld) context.getBean("helloWorld");
		helloWorld.hello();
			
		Car car1 = (Car) context.getBean("car1");
		Car car2 = (Car) context.getBean("car2");
		System.out.println(car1);
		System.out.println(car2);	
		//这种方式的缺点是只能定义一个。
		
		Persion person1 = (Persion) context.getBean("person1");
		System.out.println(person1);
		Persion person2 = (Persion) context.getBean("person2");
		System.out.println(person2);

	}
}
